package by.averianov.discounta.webapp.page.administrator;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.extensions.ajax.markup.html.tabs.AjaxTabbedPanel;
import org.apache.wicket.extensions.markup.html.tabs.AbstractTab;
import org.apache.wicket.extensions.markup.html.tabs.ITab;
import org.apache.wicket.markup.html.panel.Panel;

import by.averianov.discounta.webapp.page.BaseLayout;
import by.averianov.discounta.webapp.page.tabs.TabCard;
import by.averianov.discounta.webapp.page.tabs.TabCardType;
import by.averianov.discounta.webapp.page.tabs.TabShop;
import by.averianov.discounta.webapp.page.tabs.TabUser;

@AuthorizeInstantiation({ "administrator" })
public class Administrator extends BaseLayout {
	
	protected int selectedTab;
	protected Long selectShopId;
	protected Long selectCardId;
	protected Long selectCardTypeId;
	protected Long selectUserId;
	
	public Administrator(int selectedTab, Long selectId) {
		super(null);
		super.currentMenu = "administrator";
		this.selectedTab = selectedTab;
		
		switch (selectedTab) {
		case 0: 
			this.selectShopId = selectId;
			break;
		case 1:
			this.selectCardId = selectId;
			break;
		case 2:
			this.selectCardTypeId = selectId;
			break;
		case 3:
			this.selectUserId = selectId;
			break;
		}
	}
	
	protected void onInitialize() {
		super.onInitialize();
		
		List<ITab> tabs = new ArrayList<ITab>();
        tabs.add(new AbstractTab(getLabelAdministratorShops()) {

            @Override
            public Panel getPanel(String panelId) {
                return new TabShop(panelId, selectShopId, currentMenu);
            }

        });

        tabs.add(new AbstractTab(getLabelAdministratorCards()) {

            @Override
            public Panel getPanel(String panelId) {
                return new TabCard(panelId, selectCardId, currentMenu);
            }

        });
        
        tabs.add(new AbstractTab(getLabelAdministratorCardTypes()) {

            @Override
            public Panel getPanel(String panelId) {
                return new TabCardType(panelId, selectCardTypeId, currentMenu);
            }

        });

        tabs.add(new AbstractTab(getLabelAdministratorUsers()) {

            @Override
            public Panel getPanel(String panelId) {
                return new TabUser(panelId, selectUserId, currentMenu);
            }

        });

        AjaxTabbedPanel ajaxTabbedPanel = new AjaxTabbedPanel("tabs", tabs);
        ajaxTabbedPanel.setSelectedTab(selectedTab);
        add(ajaxTabbedPanel);
	}
}